package cn.devzyh.service.impl;

import cn.devzyh.dao.PromotionSpaceMapper;
import cn.devzyh.domain.PromotionSpace;
import cn.devzyh.service.PromotionSpaceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
import java.util.UUID;

@Service
public class PromotionSpaceServiceImpl implements PromotionSpaceService {

    @Autowired
    private PromotionSpaceMapper promotionSpaceMapper;

    @Override
    public List<PromotionSpace> findAllPromotionSpace() {

        return promotionSpaceMapper.findAllPromotionSpace();
    }

    @Override
    public void savePromotionSpace(PromotionSpace space) {

        Date now = new Date();
        space.setSpaceKey(UUID.randomUUID().toString().replaceAll("-", ""));
        space.setCreateTime(now);
        space.setUpdateTime(now);

        promotionSpaceMapper.savePromotionSpace(space);
    }

    @Override
    public void updatePromotionSpace(PromotionSpace space) {

        space.setUpdateTime(new Date());

        promotionSpaceMapper.updatePromotionSpace(space);
    }

    @Override
    public PromotionSpace findOneById(Integer id) {

        return promotionSpaceMapper.findOneById(id);
    }
}
